//
//  RDPageViewController.m
//  readApp
//
//  Created by 飞猪 on 2018/8/16.
//  Copyright © 2018年 😝😝😝😝😝. All rights reserved.
//

#import "RDContainerPageViewController.h"

@interface RDContainerPageViewController ()

@end

@implementation RDContainerPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
  self.view.backgroundColor = [UIColor clearColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

@interface RDPageViewController ()

@end

@implementation RDPageViewController

- (instancetype)init {
  self = [super init];
  if (self) {
    _index = 1;
//    _chapterBelong = 1;
  }
  return self;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  
  self.view.backgroundColor = [UIColor whiteColor];
  
  if (self.backgroundImage) {
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    imageView.image = self.backgroundImage;
    [self.view insertSubview:imageView atIndex:0];
  }
  
}

@end

@interface RDBackViewController ()

@end

@implementation RDBackViewController

- (instancetype)init {
  self = [super init];
  if (self) {
    _index = 1;
//    _chapterBelong = 1;
  }
  return self;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  
  self.view.backgroundColor = [UIColor whiteColor];
  
  if (self.backgroundImage) {
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageView.image = self.backgroundImage;
    [self.view addSubview:imageView];
  }
  
}

- (void)grabViewController:(RDPageViewController *)viewController {
  self.index = viewController.index;
  self.chapterBelong = viewController.chapterBelong;
  CGRect rect = viewController.view.bounds;
  
  UIGraphicsBeginImageContextWithOptions(rect.size, true, 0.0);
  CGContextRef context = UIGraphicsGetCurrentContext();
  CGAffineTransform transform = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0,  rect.size.width, 0.0);
  CGContextConcatCTM(context, transform);
  
  [viewController.view.layer renderInContext:context];
  self.backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
}

@end

